package com.zzsy.shoppingpro.home.acitivty;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.zzsy.shoppingpro.R;
import com.zzsy.shoppingpro.app.Config;
import com.zzsy.shoppingpro.base.BaseActivity;
import com.zzsy.shoppingpro.commentactivity.GoodsInfoActivity;
import com.zzsy.shoppingpro.home.adapter.HotGridViewAdapter;
import com.zzsy.shoppingpro.home.bean.GoodsBean;
import com.zzsy.shoppingpro.home.bean.HomeBean;
import com.zzsy.shoppingpro.home.customs.FitScrollGridView;

import java.util.ArrayList;

public class HotDeticActivity extends BaseActivity {

    private ArrayList<HomeBean.ResultBean.HotInfoBean>  hotList;
    private GridView gvHot;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hot_detic);
        hotList = new ArrayList<>();
        initData();
        initUI();
    }

    /**
     * 初始化数据
     * */
    private void initData() {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        hotList = (ArrayList<HomeBean.ResultBean.HotInfoBean>) bundle.getSerializable("hotbean");
    }

    /**
     * 初始化数据
     * */
    private void initUI() {

        TextView tvNameTitle = findViewById(R.id.title);
        tvNameTitle.setText("热卖列表");
        gvHot = findViewById(R.id.gv_hots);
        HotGridViewAdapter hotGridViewAdapter = new HotGridViewAdapter(HotDeticActivity.this,hotList);
        gvHot.setAdapter(hotGridViewAdapter);
        gvHot.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String cover_price = hotList.get(position).getCover_price();
                String name = hotList.get(position).getName();
                String figure = hotList.get(position).getFigure();
                String product_id = hotList.get(position).getProduct_id();
                GoodsBean goodsBean = new GoodsBean(name, cover_price, figure, product_id);

                Intent intent = new Intent(HotDeticActivity.this, GoodsInfoActivity.class);
                intent.putExtra(Config.GOODS_BEAN, goodsBean);
               startActivity(intent);
            }
        });
    }
}
